package com.ruoyi.truth.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.truth.domain.GovUser;
import com.ruoyi.truth.service.IGovUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 主页Controller
 *
 * @author ruoyi
 * @date 2023-06-28
 */
@RestController
@RequestMapping("/truth/govhome")
public class GovUserController extends BaseController {
    @Autowired
    private IGovUserService govUserService;

    /**
     * 查询主页列表
     */
    @PreAuthorize("@ss.hasPermi('truth:govhome:list')")
    @GetMapping("/list")
    public TableDataInfo list(GovUser govUser) {
        startPage();
        List<GovUser> list = govUserService.selectGovUserList(govUser);
        return getDataTable(list);
    }

    /**
     * 导出主页列表
     */
    @PreAuthorize("@ss.hasPermi('truth:govhome:export')")
    @Log(title = "主页", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GovUser govUser) {
        List<GovUser> list = govUserService.selectGovUserList(govUser);
        ExcelUtil<GovUser> util = new ExcelUtil<GovUser>(GovUser.class);
        util.exportExcel(response, list, "主页数据");
    }

    /**
     * 获取主页详细信息
     */
    @PreAuthorize("@ss.hasPermi('truth:govhome:query')")
    @GetMapping(value = "/{govUserid}")
    public AjaxResult getInfo(@PathVariable("govUserid") Long govUserid) {
        return success(govUserService.selectGovUserByGovUserid(govUserid));
    }

    /**
     * 新增主页
     */
    @PreAuthorize("@ss.hasPermi('truth:govhome:add')")
    @Log(title = "主页", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GovUser govUser) {
        return toAjax(govUserService.insertGovUser(govUser));
    }

    /**
     * 修改主页
     */
    @PreAuthorize("@ss.hasPermi('truth:govhome:edit')")
    @Log(title = "主页", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GovUser govUser) {
        return toAjax(govUserService.updateGovUser(govUser));
    }

    /**
     * 删除主页
     */
    @PreAuthorize("@ss.hasPermi('truth:govhome:remove')")
    @Log(title = "主页", businessType = BusinessType.DELETE)
    @DeleteMapping("/{govUserids}")
    public AjaxResult remove(@PathVariable Long[] govUserids) {
        return toAjax(govUserService.deleteGovUserByGovUserids(govUserids));
    }
}
